function searchGoods()
{		
	var searchData = '';
	searchData = 's_goods_name='+$('#s_good_name').val() +"&s_class_attr=" +$("#goods_type").val();
	$.ajax(
	{
		type: "POST",
		url: "searchGoods.jsp",
		data: searchData,
		success: function(msg){
		 $("#good_id").empty();
		 $("#good_id").html(msg);
		}
	});
}
				

  function addQuantityPrice(buttonObj, tableIndex){
  var tableObj = buttonObj.parentNode.parentNode.parentNode.parentNode;
  var newRow = tableObj.insertRow(-1);
  var cell1 = newRow.insertCell(-1);
  var cell2 = newRow.insertCell(-1);
  var cell3 = newRow.insertCell(-1);
  var cell4 = newRow.insertCell(-1);
  var cell5 = newRow.insertCell(-1);
  
  cell1.innerHTML = '&nbsp;';
  cell2.innerHTML = ' 数量： <input name="quantity[' + tableIndex + '][]" type="text" value="0" maxlength="10"/> ';
  cell3.innerHTML = ' 价格： <input name="price[' + tableIndex + '][]" type="text" value="0" maxlength="10"/> ';
  cell4.innerHTML = ' <input type="button" class="button" value=" - " onclick="dropQuantityPrice(this)" />';
  cell5.innerHTML = '&nbsp;';
  
}
function dropQuantityPrice(buttonObj){

  var trObj = buttonObj.parentNode.parentNode;
  var tableObj = trObj.parentNode.parentNode;
  tableObj.deleteRow(trObj.rowIndex);
}


function checkSub(){

		var temp = getMix("quantity[0][]","price[0][]");
		$("#prices").val(temp);
		if($("select[name='good_id'] option:selected").text() != ''){
		$("#good_name").val($("select[name='good_id'] option:selected").text());
		}else{
		alert("请选择商品！");
		}
	
	if(document.getElementById('good_id').value==''){
		alert('批发商品名不能为空！');
		document.getElementById('good_id').focus();
		return false;
	}

	if(document.getElementById('price-div').value==''){
		alert('批发数量、价格不能为空！');
		document.getElementById('price-div').focus();
		return false;
	}
	
	document.addForm.submit();
}

//数量价格拼串操作
// var pp=getMix("quantity[0][]","price[0][]");
//if(pp!="0"){document.getElementById('prices').value=pp;}
function getMix(quantity,price){
	var result="";
	var eles = document.forms['addForm'].elements;
	for (var i = 0; i < eles.length; i++){
	

	
		if (eles[i].type=="text" && eles[i].name==quantity){
			if(eles[i+1].type=="text" && eles[i+1].name==price){
				if(eles[i].value==""){
					alert("数量不能为空且必须是数字！");
					eles[i].value="";
     				eles[i].focus();
     				return 0;
     				break;
				}else{
					if(eles[i+1].value==""){
						alert("价格不能为空且必须是数字！");
						eles[i+1].value="";
	     				eles[i+1].focus();
	     				return 0;
	     				break;
					}else{
						result=result+eles[i].value+","+eles[i+1].value+"|";
						i=i+1;
					}
				}
			}
		}
	}
	return result;
}

function search(){
	//TODO
	document.indexForm.submit();
}
